package org.tnaggs.project.validate;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import org.tnaggs.project.model.PasswordChange;

public class PasswordValidator implements Validator {

	@Override
	public boolean supports(Class<?> arg0) {
		return PasswordChange.class.equals(arg0);
	}

	@Override
	public void validate(Object arg0, Errors errors) {
		PasswordChange passCh = (PasswordChange)arg0;

		if(!passCh.getFirstAttempt().equalsIgnoreCase(passCh.getSecondAttempt())) {
			errors.rejectValue("secondAttempt", "passwordNotSame", "The password must be the same");
		} 
	}

}
